package gestioneAccount.web.beans;

import gestione.mgrCliente.ClienteMgr;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import org.apache.commons.codec.digest.DigestUtils;

import dataTransferOblect.ClienteDTO;



@ManagedBean(name="rimozioneAccountBean")
@RequestScoped
public class RimozioneAccountBean {
	
	@EJB
	private ClienteMgr clienteMgr;

	private ClienteDTO cliente;
	
	
	public RimozioneAccountBean() {
		cliente = new ClienteDTO();
		
	}

	public ClienteDTO getCliente() {
		return cliente;
	}

	public void setCliente(ClienteDTO cliente) {
		this.cliente = cliente;
	}
	
	
	public String eliminaAccount() {
		/*String usernameReal;
		String usernameTry;
		usernameReal=clienteMgr.getPrincipalUsername();
		usernameTry=getCliente().getUsername();
		*/if (clienteMgr.getPrincipalUsername().equals(getCliente().getUsername())&&clienteMgr.getClienteDTO().getPassword().equals(DigestUtils.sha256Hex(getCliente().getPassword()))){
		clienteMgr.unregister();
		FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
	    return "/home?faces-redirect=true";
		}else{
			return "index.xhtml?faces-redirect=true";
		}
	}
	
	

}
